<template>
    <div>
        <div>
            <img src="../../../static/images/uploadImg2.png" @click="uploadPic" alt=""/>
        </div>
    </div>
</template>

<script type="text/ecmascript-6">
    export default {
        name: "cameras-and-albums",
        data() {
            return {
                imgList: [],
                datas: new FormData(),
                files: 0,
                size: 0
            }
        },
        mounted() {
            //将要给原生调用的方法挂载到 window 上面
            window.handlegetupload = this.handlegetupload;
        },
        methods: {
            uploadPic() {
                let param = {type: 1, callback: 'handlegetupload'}
                let paramJSON = JSON.stringify(param);
                try {
                    if (this.isApple()) {
                        webkit.messageHandlers[method].postMessage(paramJSON);
                    } else {
                        UFFClient.upload(paramJSON);
                    }
                } catch (e) {
                    console.log(e,'调用原生js失败');
                    if (param && param.callback) {
                        eval(`${param.callback}(null);`);
                    }
                }

            },

            handlegetupload(data) {
                this.$emit('pictrueUrl', data && data.url ? data.url : '')
            },

            //是否ios系统
            isApple() {
                let userAgent = navigator.userAgent.toLowerCase();
                if (userAgent.indexOf("ios") != -1 || userAgent.indexOf("iphone") != -1 || userAgent.indexOf("ipad") != -1) {
                    return true;
                }
                return false;
            }

        },

    }
</script>
